package logic

import (
	"context"
	"merchant/models/mysql"

	"merchant/merchantmanagerrpc/internal/svc"
	"merchant/merchantmanagerrpc/merchantmanagerrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MerchantAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMerchantAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MerchantAddLogic {
	return &MerchantAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MerchantAddLogic) MerchantAdd(in *merchantmanagerrpc.MerchantAddRequest) (*merchantmanagerrpc.MerchantAddResponse, error) {
	// todo: add your logic here and delete this line

	merchant := mysql.Merchant{
		Name:  in.Name,
		Cate:  in.Cate,
		Timed: in.Timed,
	}

	err := mysql.DB.Debug().Create(&merchant).Error

	if err != nil {
		return nil, err
	}

	return &merchantmanagerrpc.MerchantAddResponse{
		Id: int64(merchant.ID),
	}, nil
}
